package com.jinlejia.erp.ui.mine.pushmoney;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jinlejia.erp.R;
import com.jinlejia.erp.base.ApiConfig;
import com.jinlejia.erp.base.MapCallBack;
import com.jinlejia.erp.databinding.ActivityDetailPushMoneyBinding;
import com.jinlejia.erp.utils.DataFilter;
import com.jinlejia.erp.utils.DateUtil;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.Map;

import okhttp3.Call;
import okhttp3.MediaType;

public class DetailPushMoneyActivity extends AppCompatActivity {
    private String commissionType;
    private String costId;
    private ActivityDetailPushMoneyBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_detail_push_money);
        commissionType = getIntent().getStringExtra("commissionType");
        costId = getIntent().getStringExtra("costId");
        binding.backBtn.setOnClickListener(view -> finish());
        getData();
    }


    private void getData() {
        final JSONObject json = new JSONObject();
        json.put("commissionType", commissionType);
        json.put("costId", costId);
        OkHttpUtils
                .postString()
                .url(ApiConfig.MY_COMMISSION_DETAIL)
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .content(json.toString())
                .build()
                .execute(new MapCallBack() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        call.cancel();
                        e.printStackTrace();
                    }

                    @Override
                    public void onResponse(Map<String, Object> response, int id) {
                        if (DataFilter.filter(DetailPushMoneyActivity.this, response)) {
                            JSONObject jsonObject = JSON.parseObject(response.get("data").toString());
                            binding.pactCode.setText(jsonObject.getString("pactCode"));
                            binding.houseAddress.setText(jsonObject.getString("address"));
                            //成交类型
                            switch (jsonObject.getString("tradeType")) {
                                case "ershoufang":
                                    binding.cjType.setText("二手房");
                                    break;
                                case "xinfang":
                                    binding.cjType.setText("一手房");
                                    break;
                                case "zulin":
                                    binding.cjType.setText("租房");
                                    break;
                                case "jinrong":
                                    binding.cjType.setText("垫资");
                                    break;
                            }
//                            cjType.setText( jsonObject.getString("tradeType") );
                            binding.cjTime.setText(DateUtil.getTime(jsonObject.getString("tradeTime"), "yyyy-MM-dd HH:mm:ss"));
                            binding.pushMoneyMan.setText(jsonObject.getString("name"));
                            binding.pushMoneyManStore.setText(jsonObject.getString("shareStoreName"));
                            binding.pushMoneyAccount.setText(jsonObject.getString("amount"));

                            //提成类型
                            String commissionType = "";
                            switch (jsonObject.getString("commissionType")) {
                                case "pin":
                                    commissionType = "个人提成";
                                    break;
                                case "trainingMangerPin":
                                    commissionType = "带训提成";
                                    break;
                                case "developTrainingManagerPin":
                                    commissionType = "培育带训经理提成";
                                    break;
                                case "developCityPartnerPin":
                                    commissionType = "培育城市合伙人提成";
                                    break;
                                case "developCityDeputyManagerPin":
                                    commissionType = "培育城市副总经理提成";
                                    break;
                                case "developCityManagerPin":
                                    commissionType = "培育城市总经理提成";
                                    break;
                                case "developPin":
                                    commissionType = "培育分成人提成";
                                    break;
                            }
                            binding.pushMoneyType.setText(commissionType);
                            binding.pushMoneyPay.setText(jsonObject.getString("commissionAmount"));
                            binding.pushMoneyBack.setText(jsonObject.getString("commissionRepair"));
                        }
                    }
                });
    }
}
